/**
 * 酒店相关API服务
 */
import api from './index';
import { ApiResponse, Hotel, PaginationData, Room } from './types';

/**
 * 搜索酒店
 */
export interface SearchHotelParams {
  city?: string;
  district?: string;
  checkInDate?: string;
  checkOutDate?: string;
  guests?: number;
  minPrice?: number;
  maxPrice?: number;
  rating?: number;
  facilities?: string[];
  page?: number;
  pageSize?: number;
}

export const searchHotels = (params: SearchHotelParams): Promise<ApiResponse<PaginationData<Hotel>>> => {
  return api.get('/hotels', { params });
};

/**
 * 获取酒店详情
 */
export const getHotelDetail = (id: string): Promise<ApiResponse<Hotel>> => {
  return api.get(`/hotels/${id}`);
};

/**
 * 获取酒店房间列表
 */
export const getHotelRooms = (hotelId: string, params?: {
  checkInDate?: string;
  checkOutDate?: string;
  guests?: number;
}): Promise<ApiResponse<Room[]>> => {
  return api.get(`/hotels/${hotelId}/rooms`, { params });
};

/**
 * 获取热门/推荐酒店
 */
export const getRecommendedHotels = (city?: string, limit = 10): Promise<ApiResponse<Hotel[]>> => {
  return api.get('/hotels/recommended', { params: { city, limit } });
};

/**
 * 获取酒店评价
 */
export interface HotelReview {
  id: string;
  userId: string;
  username: string;
  avatar?: string;
  rating: number;
  comment: string;
  images?: string[];
  createTime: string;
  tags?: string[];
}

export const getHotelReviews = (hotelId: string, page = 1, pageSize = 10): Promise<ApiResponse<PaginationData<HotelReview>>> => {
  return api.get(`/hotels/${hotelId}/reviews`, { params: { page, pageSize } });
}; 